<?php
    $name = $this->member->first_name . ' ' . $this->member->last_name;
    $this->pageHeader('Administrer ekspertise for ' . $name);
?>

<p id="top_right_links">
    <a href="<?php echo $this->url(array('module' => 'admin', 'controller' => 'member', 'action' => 'edit', 'id' => $this->member->id), null, false); ?>" class="button"><img src="<?php echo $this->imageLink('images/icons/pencil.png'); ?>" />Rediger medlem</a>
</p>

<h1>Administrer ekspertise for "<?php echo $name; ?>"</h1>

<?php echo $this->flashMessage()->renderMessages(); ?>
<?php echo $this->courseAdded; ?>

<h2>Legg til nytt kurs</h2>
<?php
    $this->addCourseForm->setMethod('POST');
    $this->addCourseForm->setAction($this->url());
    echo $this->addCourseForm;
?>

<p>&nbsp;</p>

<h2>Registrerte kurs</h2>

<table>
    <tr>
        <th>Kurs</th>
        <th>Gyldig til</th>
        <th>&nbsp;</th>
    </tr>
<?php

if (count($this->member->MemberCourse) > 0)
{
    $nowDate = RedCross_Date::now();
    foreach ($this->member->MemberCourse as $memberCourse) :
        if ($memberCourse->Course->type == 'course') {
        if ($memberCourse->expires_date)
        {
            $expiresDate = new RedCross_Date();
            $expiresDate->import($memberCourse->expires_date);

            $expiresStr = '';
            if ($expiresDate->isEarlier($nowDate)) {
                $expiresStr = '<span style="color:red">' . $expiresDate->getDateStr() . '</span';
            } else {
                $expiresStr .= $expiresDate->getDateStr();
            }
        } else {
            $expiresStr = '-';
        }
?>
    <tr>
        <td><?php echo $memberCourse->Course->name ?></td>
        <td><?php echo $expiresStr ?></td>
        <td>
            <a href="<?php echo $this->url(array('action' => 'remove-course', 'member' => $memberCourse->member_id, 'course' => $memberCourse->course_id))?>">Fjern</a>
        </td>
    </tr>
<?php
    }
    endforeach;
} else { ?>
    <tr>
        <td colspan="3">Ingen kurs registrert</td>
    </tr>
<?php } ?>

</table>

<p>&nbsp;</p>

<h2>Legg til ny kompetanse</h2>
<?php
    $this->addCompetenceForm->setMethod('POST');
    $this->addCompetenceForm->setAction($this->url());
    echo $this->addCompetenceForm;
?>

<p>&nbsp;</p>

<h2>Registrert kompetanse</h2>

<table>
    <tr>
        <th>Kompetanse</th>
        <th>Gyldig til</th>
        <th>&nbsp;</th>
    </tr>
<?php

if (count($this->member->MemberCourse) > 0)
{
    $nowDate = RedCross_Date::now();
    foreach ($this->member->MemberCourse as $memberCourse) :
        if ($memberCourse->Course->type == 'competence') {
        if ($memberCourse->expires_date)
        {
            $expiresDate = new RedCross_Date();
            $expiresDate->import($memberCourse->expires_date);

            $expiresStr = '';
            if ($expiresDate->isEarlier($nowDate)) {
                $expiresStr = '<span style="color:red">' . $expiresDate->getDateStr() . '</span';
            } else {
                $expiresStr .= $expiresDate->getDateStr();
            }
        } else {
            $expiresStr = '-';
        }
?>
    <tr>
        <td><?php echo $memberCourse->Course->name ?></td>
        <td><?php echo $expiresStr ?></td>
        <td>
            <a href="<?php echo $this->url(array('action' => 'remove-course', 'member' => $memberCourse->member_id, 'course' => $memberCourse->course_id))?>">Fjern</a>
        </td>
    </tr>
<?php
    }
    endforeach;
} else { ?>
    <tr>
        <td colspan="3">Ingen kompetanse registrert</td>
    </tr>
<?php } ?>

</table>
